package com.syq.day2;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.function.IntBinaryOperator;
import java.util.function.IntPredicate;
import java.util.function.Supplier;

/**
 * 函数式接口：
 *  函数式接口是指只包含一个抽象方法的接口
 */
public class Sample1 {

    static class Student {
        public String name;
        public int age;
        public Student() {
        }
        public Student(String name, int age) {
            this.name = name;
            this.age = age;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public int getAge() {
            return age;
        }
        public void setAge(int age) {
            this.age = age;
        }
    }

    public static void main(String[] args) {
//        Lambda1 ld1 = (int a) -> (a & 1) == 0;
        IntPredicate ld1 = (int a) -> (a & 1) == 0;
        Lambda1 ld2 = (int a) -> BigInteger.valueOf(a).isProbablePrime(100);
        Lambda2 ld3 = (int a, int b, int c) -> a + b + c;
//        Lambda3 ld4 = (int a, int b) -> a - b;
        IntBinaryOperator ld4 = (int a, int b) -> a - b;
        Lambda3 ld5 = (int a, int b) -> a * b;
//        Lambda4<Student> ld6 = () -> new Student();
        Supplier<Student> ld6 = () -> new Student();
        Lambda4<List<Student>> ld7 = () -> new ArrayList<Student>();
//        Lambda5<String, Student> ld8 = (Student s) -> s.getName();
        Function<Student, String> ld8 = (Student s) -> s.getName();
        Lambda5<Integer, Student> ld9 = (Student s) -> s.getAge();
    }

    @FunctionalInterface
    interface Lambda5<T, R> {
        T test(R r);
    }

    @FunctionalInterface
    interface Lambda4<T> {
        T test();
    }

    @FunctionalInterface
    interface Lambda3 {
        int test(int a, int b);
    }

    @FunctionalInterface
    interface Lambda2 {
        int test(int a, int b, int c);
    }

    @FunctionalInterface
    interface Lambda1 {
        boolean test(int a);
    }
}
